package com.example.peanutsubway.web;

import com.alibaba.fastjson.JSONObject;
import com.example.peanutsubway.annotation.ResponseTypeAnnotation;
import com.example.peanutsubway.entity.GameTypeInfo;
import com.example.peanutsubway.entity.PageInfo;
import com.example.peanutsubway.myEnum.ResponseEnum;
import com.example.peanutsubway.service.GameTypeInfoService;
import com.example.peanutsubway.service.impl.GameTypeInfoImpl;

import javax.servlet.annotation.WebServlet;
import java.util.List;

/**
 * @Author：liyangsong
 * @Version：1.0
 * @Date：2021/10/11-21:40
 * @Since:jdk1.8
 * @Description:
 */

@WebServlet("/type.do")
public class GameTypeServlet extends BaseServlet<GameTypeInfo> {
    private GameTypeInfoService gameTypeInfoService = new GameTypeInfoImpl();

    @ResponseTypeAnnotation(type = ResponseEnum.AJAX)
    public String gameType(GameTypeInfo gameTypeInfo){
        List<GameTypeInfo> gametypelist = gameTypeInfoService.gametypelist();
        String jsonString = JSONObject.toJSONString(gametypelist);
        return jsonString;
    }

    @ResponseTypeAnnotation(type = ResponseEnum.AJAX)
    public String show(GameTypeInfo gameTypeInfo){
        String nowPage = request.getParameter("nowPage");
        String pageNum = request.getParameter("pageSize");
        PageInfo pageInfo = gameTypeInfoService.showAllGameType(gameTypeInfo, nowPage, pageNum);
        String jsonString = JSONObject.toJSONString(pageInfo);
        return jsonString;
    }

    @ResponseTypeAnnotation(type = ResponseEnum.AJAX)
    public String addGameType(GameTypeInfo gameTypeInfo){
        Boolean aBoolean = gameTypeInfoService.addGameType(gameTypeInfo);
        String message = aBoolean?"添加成功":"添加失败";
        return message;
    }

    @ResponseTypeAnnotation(type = ResponseEnum.AJAX)
    public String updateGameType(GameTypeInfo gameTypeInfo){
        Boolean aBoolean = gameTypeInfoService.updateGameType(gameTypeInfo);
        String message = aBoolean?"修改成功":"修改失败";
        return message;
    }
    @ResponseTypeAnnotation(type = ResponseEnum.AJAX)
    public String deleteGameType(GameTypeInfo gameTypeInfo){
        Boolean aBoolean = gameTypeInfoService.deleteGameType(gameTypeInfo.getTypeId());
        String message = aBoolean?"删除成功":"删除失败";
        return message;
    }
}
